﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BDSimpleStatus.Models
{
    public class RequiresAuthenticationAttribute : ActionFilterAttribute 
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string LoginPath = "~/Home/LogIn/?ReturnURL=" + HttpContext.Current.Server.UrlEncode((HttpContext.Current.Request.ServerVariables["URL"]));
            //redirect if not authenticated
            Authentication auth = new Authentication();
            if (!auth.isAuthenticated())
            {
                filterContext.HttpContext.Response.Redirect(LoginPath, true);
            }
            
            
             /*   
             Authentication auth = new Authentication();
            if (!auth.isAuthenticated())
            {
                filterContext.HttpContext.Response.Redirect(LoginPath, true);
            }
              * */
        }
    }
}